/* Consola - Main.cc
 * Copyright (c) 2009 The Consola Authors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 * 
 */
#include "Consola/StdAfx.h"
#include "Consola/resource.h"
#include "Consola/Frames/MainFrame.h"
#include "Consola/Extern.h"

CAppModule g_AppModule;

static int Run(LPWSTR lpCMdLine, int nCmdShow)
{
    CMessageLoop MessageLoop;

    g_AppModule.AddMessageLoop(&MessageLoop);

    CMainFrame frameMain;

    if (frameMain.CreateEx() == NULL) {
        ATLTRACE(L"Failed to create the main window frame.\n");
        return 0;
    }

    frameMain.ShowWindow(SW_MAXIMIZE);
    int nRet = MessageLoop.Run();
    g_AppModule.RemoveMessageLoop();

    return nRet;
}

int WINAPI wWinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPWSTR lpCmdLine, __in int nShowCmd )
{
    InitConsola();

    ::InitCommonControls();
    g_AppModule.Init(NULL, hInstance);

    int nRet = Run(lpCmdLine, nShowCmd);
    g_AppModule.Term();

    return nRet;
}

/* EOF */

